package wj;

import java.util.List;

public class WJValue {

	public static final WJValue NULL = new WJValue();
	
	private Object value;
	
	private WJValue(){
		value = new Object();
	}
	
	public WJValue(Object o){
		value = o;
	}
	
	//getters
	public Object getValue(){
		return value;
	}
	
	//converters
	public boolean toBoolean(){
		return Boolean.parseBoolean(value.toString());
	}
	
	public double toDouble(){
		return Double.parseDouble(value.toString());
	}
	
	public int toInt(){
		return Integer.parseInt(value.toString());
	}
	
	public String toString(){
		if(isNull())
			return "NULL";
		if(value instanceof Double)
			if(Math.floor((double) value) == (double)value){
				String str = String.valueOf(value);
				return str.substring(0, str.length() - 2);
			}
		return String.valueOf(value);
	}
	
	@SuppressWarnings("unchecked")
    public List<WJValue> toList(){
    	return (List<WJValue>)value;
    }
	

	//checkers
	public boolean isBoolean() {
        return value instanceof Boolean;
    }

    public boolean isNumber() {
        return value instanceof Number;
    }
    
    public boolean isString() {
        return value instanceof String;
    }

    public boolean isList() {
        return value instanceof List<?>;
    }

    public boolean isNull() {
        return this == NULL || value == null;
    }


}
